package com.workflow.workflowproject.listener;

import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.ProcessEngine;
import org.flowable.engine.ProcessEngines;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.JavaDelegate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 消息通知监听
 */
@Slf4j
@Component
public class NotifyTaskService implements JavaDelegate {

    @Autowired
    private ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

    private static NotifyTaskService ccTaskService;
    @PostConstruct
    public void init(){
        ccTaskService = this;
        ccTaskService.processEngine =this.processEngine;
    }

    @Override
    public void execute(DelegateExecution execution) {
        log.info("触发消息通知监听》》》》");
        //1、环境信息
        //流程任务ID
        String taskProcessId = execution.getId();
        log.info("流程任务ID:" + taskProcessId);
        //流程id
        String processInstanceId = execution.getProcessInstanceId();
        log.info("抄送流程ID:" + processInstanceId);
        //该任务 id
        String taskId = execution.getCurrentActivityId();
        log.info("抄送任务ID:" + taskId);
        //该任务名称
        String name  = execution.getEventName();
        log.info("抄送名称:" + name);

    }
}
